//
//  JBWUserRecordListView.m
//  JBWDSK
//
//  Created by 崔志伟 on 2018/7/27.
//  Copyright © 2018年 崔志伟. All rights reserved.
//

#import "JBWUserRecordListView.h"
#import "JBWUserRecordListViewTableViewCell.h"

@interface JBWUserRecordListView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSMutableArray  * dataArray ;

@end

@implementation JBWUserRecordListView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self  = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        UIView *centerLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self .frame), 1)];
        centerLine.backgroundColor = [UIColor orangeColor];
        [self  addSubview:centerLine];
        self.layer.cornerRadius = 5.f;
        self.layer.masksToBounds = YES;
        [self setupTabelView];
    }
    return self;
}

- (void)setupTabelView{
    self.dataArray = [NSMutableArray arrayWithArray:@[@"1666666666666",@"1666666666666",@"1666666666666"]];
    UITableView *tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 1, self.frame.size.width, self.frame.size.height)];
    tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tabelView registerClass:[JBWUserRecordListViewTableViewCell class] forCellReuseIdentifier:@"JBWUserRecordListViewTableViewCell"];
    tabelView.dataSource = self;
    tabelView.delegate = self;
    [self addSubview:tabelView];
    tabelView.tableFooterView = [self setUpFooterView];


}

- (UIView *)setUpFooterView{
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 44)];
    
    UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, MAIN_BG_VIEW_WIDTH-40, 44)];
    contentLabel.font = [UIFont systemFontOfSize:15];
    contentLabel.textColor = [UIColor grayColor];
    contentLabel.text = @"历史账号";
    [footerView addSubview:contentLabel];
    UIButton *footerViewBtn  = [[UIButton alloc]initWithFrame:footerView.bounds];
    [footerViewBtn addTarget:self action:@selector(footerViewBtnAcrion) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:footerViewBtn];
    
    return footerView;
}

- (void)footerViewBtnAcrion{
    
    if (self.userRecordListBlock) {
        self.userRecordListBlock();
    }
    
}

#pragma mark == UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.dataArray.count;
}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    JBWUserRecordListViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JBWUserRecordListViewTableViewCell" forIndexPath:indexPath];
    cell.contentLabel.text = self.dataArray[indexPath.row];
    cell.deleUserRecordBlock = ^(JBWUserRecordListViewTableViewCell *cell) {
      NSIndexPath *indexPath =   [tableView indexPathForCell:cell];
        [self.dataArray removeObjectAtIndex:indexPath.row];
        [tableView reloadData];
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 45;
}
@end
